package com.example.demo.behavior.observer;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.Observable;
import java.util.Observer;

/**
 * @Desc:
 * @Author zzz
 * @Date 2021/2/24
 * @Version V1.0
 */
@Data
@AllArgsConstructor
public class Movie extends Observable {

    String name;

    public void follow(Observer observer) {
        super.addObserver(observer);
    }

    public void unfollow(Observer observer) {
        super.deleteObserver(observer);
    }

    public void info() {
        System.out.println(String.format("有%d个人关注了%s", super.countObservers(), name));
    }

    public void publish() {
        super.setChanged();
        super.notifyObservers(name);
    }

}
